<template>
    <div id="member">
        <el-col :span="24" class="action-bar">
            <el-button type="primary" size="medium" @click="reback">返回</el-button>
            <el-button type="primary" size="medium" @click="signatureVisible=true">添加</el-button>
        </el-col>
        

        <!-- 列表 -->
        <el-table
            :data="tableData"
            style="width: 100%">
            <el-table-column
                prop="name"
                label="名称"
                width="200"
                >
            </el-table-column>
            <!--<el-table-column-->
                    <!--prop="circle_name"-->
                    <!--label="所属圈子"-->
                    <!--width="200"-->
            <!--&gt;-->
            <!--</el-table-column>-->
            <el-table-column
                prop="created_at"
                label="创建时间"
                width="200"
                >
            </el-table-column>
            <!-- <el-table-column
                prop="status_name"
                label="排序"
                width="100"
                >
            </el-table-column> -->
            
            <el-table-column label="操作" width='143'>
                <template slot-scope="scope">
                    <el-button type='text' @click="deletePost(scope.row.article_classify_id)">删除</el-button>
                </template>
            </el-table-column>
            
        </el-table>

		<el-dialog title="帖子类型" :visible.sync="signatureVisible" @close="initData">
            <el-form>
                <el-form-item label="帖子类型">
                    <el-select v-model="postType" clearable placeholder="帖子类型" style="margin:0 20px;">
                        <el-option
                        v-for="item in postTypeOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submit" >提交</el-button>
			</div>
		</el-dialog>
    </div>
</template>
<script>
export default {
    name:'member',
    data() {
        return {
            name:'',
            signatureVisible:false,//编辑弹窗
            circleTypeId:'',//选中的用户id
            tableData: [{}],
            page:1,
            postType:'',
            postTypeOptions:[],
            totalPage:0,
            articleClassifyList:[],
            loading:false,
        }
    },
    methods: {      
        reback(){
            this.$router.go(-1)
        },
        pageChange(e){
			//翻页
			this.page=e;
			this.getUserAnswerList();
        },
        async submit(){
            let params={
                circle_id:this.circleId,
                classify_id:this.postType
            }
            let res=await this.$api.adminSetCircleSupportClassify(params)
            if(res.data.level=='success'){
                this.$message({
                    type:'success',
                    message:res.data.message
                })
                this.signatureVisible = false
                this.geThisClassifyList()
            }else{
                this.$message({
                    type:'error',
                    message:res.data.message
                })
                
            }
        },
        async deletePost(id){
            //删除圈子类型
             let judge=null
            try {
              judge=  await this.$confirm('删除该圈子?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
                })
            } catch (error) {
                judge='cancel'
            }
            if(judge=='confirm'){
                let res=await this.$api.delCircleSupportClassify({id:id});
                
                if(res.data.level=='success'){
                        this.$message({
                            type:'success',
                            message:res.data.message
                        })
                        this.signatureVisible=false
                        this.geThisClassifyList()
                    }else{
                        this.$message({
                            type:'error',
                            message:res.data.message
                        })
                    }
              
            }
        },
        async getArticleClassifyList(){
            //获取可选类型的列表
            let res=await this.$api.getArticleClassifyList()
            if(res.data.level=='success'){
                this.postTypeOptions=res.data.data.map(item=>{
                    return{
                        value:item.id,
                        label:item.name
                    }
                })
            }
        },
        async searchClassifyList(searchText){
            //获取可选类型的列表
            let params = {
                keyword:searchText
            }
            let res=await this.$api.getArticleClassifyList(params)
            if(res.data.level=='success'){
                this.articleClassifyList=res.data.data;
                // this.totalPage=res.data.page_info.total;
            }
        },
        async geThisClassifyList(){
            //获取可选类型的列表
            let res=await this.$api.getArticleClassifyList({circle_id:this.circleId})
            if(res.data.level=='success'){
                this.tableData=res.data.data;
                // this.totalPage=res.data.page_info.total;
            }
        },
        initData(){

        }

    },
    mounted() {
        this.circleId=this.$route.query.id;
        this.getArticleClassifyList()
        this.geThisClassifyList()
    },
}
</script>
<style lang="scss" scoped>
.screen{
          margin-top: -10px !important;
      }
    .action-bar{
			background-color: #f2f2f2;
			height: 60px;
			margin: 10px 0px;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			padding-left: 20px;
			.action-bar-input{
				width: 250px;
				margin-right: 14px;
      }
      .task-form-text{
				color: #666666;
			}
		}
		.el-table-style{
			width: 100%;
			border: 1px solid #f2f2f2;
		}
		.footer-bar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #f2f2f2;
			padding: 8px;
			margin: 10px 0px;
			box-sizing: border-box;
		}
		.dialog-footer{
			text-align: center;
		}
		.executorList{
			display: flex;
			flex-wrap: wrap;
			div{
				margin:10px;
				border:1px solid #eee;
				border-radius: 5px;
				padding:5px 10px;
			}
		}
</style>